﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace SFJDManagement
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Win_Number : Window
    {
        double scWidth = SystemParameters.PrimaryScreenWidth;
        double scHeight = SystemParameters.PrimaryScreenHeight;
        string code;
        int number;

        public Win_Number(string code, string number)
        {
            InitializeComponent();
            this.code = code;
            this.number = Int32.Parse(number);
            ini();
        }

        private void ini()
        {
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            AllowsTransparency = true;
            WindowStyle = WindowStyle.None;
            Grid0.Background = Brushes.Transparent;
            Opacity = 1;
            //Background = Brushes.Transparent;
            Background = Brushes.Transparent;
            ShowNumber();
        }

        private void ShowNumber()
        {
            Grid0.Children.Clear();
            Width = scWidth;
            Height = scHeight;

            ////////////报告编码////////////
            Grid0.Children.Add(GetCodeShadow(code));
            Grid0.Children.Add(GetCodeForground(code));
            ////////////报告编码////////////

            ////////////报告排号////////////
            Label labNumber_Shadow = new Label()
            {
                FontSize = 300,
                Content = number.ToString(),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, scHeight / 2 - 50, 0, 0),
                Opacity = 0.8,
            };
            Grid0.Children.Add(labNumber_Shadow);
            Label labNumber = new Label()
            {
                FontSize = 300,
                Foreground = Brushes.Goldenrod,
                Content = number.ToString(),
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, scHeight / 2 - 60, 10, 0),
            };
            Grid0.Children.Add(labNumber);
            ////////////报告排号////////////

            ////////////关闭按键////////////
            Button but = new Button();
            but.Content = "关 闭";
            but.FontSize = 40;
            but.Width = 200;
            but.Height = 100;
            but.HorizontalAlignment = HorizontalAlignment.Right;
            but.VerticalAlignment = VerticalAlignment.Bottom;
            but.Margin = new Thickness(0, 0, 50, 50);
            but.Click += But_Click;
            Grid0.Children.Add(but);
            ////////////关闭按键////////////
        }

        private StackPanel GetCodeForground(string code)
        {
            StackPanel panel = new StackPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, scHeight / 2 - 208, 8, 0),//设置前景偏移
                Orientation = Orientation.Horizontal,
            };
            panel.Children.Add(GetLabel(code.Substring(0, code.Length - 2), Brushes.Goldenrod));
            panel.Children.Add(GetLabel(code.Substring(code.Length - 2, 2), Brushes.Red));
            return panel;
        }

        private StackPanel GetCodeShadow(string code)
        {
            StackPanel panel = new StackPanel()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                VerticalAlignment = VerticalAlignment.Top,
                Margin = new Thickness(0, scHeight / 2 - 200, 0, 0),
                Orientation = Orientation.Horizontal,
                Opacity = 0.8,
            };
            panel.Children.Add(GetLabel(code.Substring(0, code.Length - 2), Brushes.Black));
            panel.Children.Add(GetLabel(code.Substring(code.Length - 2, 2), Brushes.Black));
            return panel;
        }

        private Label GetLabel(string str, Brush brush)
        {
            return new Label()
            {
                FontSize = 150 * scWidth / 1920,
                Foreground = brush,
                Content = str,
            };
        }

        private void But_Click(object sender, RoutedEventArgs e)
        {
            Page_Register.instance.resetData();
            Dispatcher.Thread.Abort();//这句能关闭多线程中开启的自身线程,关闭后不会停留在主进程
            Close();
        }
    }
}
